﻿package 
{

	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	import flash.utils.Timer;
	import flash.events.TimerEvent;

	public class FightMC extends MovieClip
	{
		public var playerArray:Array = null;
		public var playerPetArray:Array = null;
		public var enemyArray:Array = null;
		public var enemyPetArray:Array = null;
		public var textFiled:TextField = null;

		public var time:int = 0;
		public var timer:Timer = null;

		public var number:Array = null;

		public var buttons:Array = null;


		public static const READY:int = 0;
		public static const COMMNAD:int = 1;
		public static const WAIT:int = 2;
		public static const RESULT:int = 3;
		public static const OVER:int = 4;


		public function FightMC()
		{
			// constructor code

			timer = new Timer(1000);
			timer.stop();
			timer.addEventListener( TimerEvent.TIMER , onTimer );

			playerArray = new Array();
			playerPetArray = new Array();
			enemyArray = new Array();
			enemyPetArray = new Array();
			buttons = new Array();


			textFiled = new TextField();
			textFiled.mouseEnabled = false;
			textFiled.textColor = 0xFF00FF;
			playerCommandMC.addChild( textFiled );

			playerCommandMC.attackButton.addEventListener( MouseEvent.CLICK , onAttackButtonClick );
			playerCommandMC.attackButton.addEventListener( MouseEvent.MOUSE_MOVE , onButtonMouseMove );
			playerCommandMC.attackButton.addEventListener( MouseEvent.MOUSE_OUT , onMouseOut );
			playerCommandMC.magicButton.addEventListener( MouseEvent.CLICK , onMagicButtonClick );
			playerCommandMC.magicButton.addEventListener( MouseEvent.MOUSE_MOVE , onButtonMouseMove );
			playerCommandMC.magicButton.addEventListener( MouseEvent.MOUSE_OUT , onMouseOut );
			playerCommandMC.skillButton.addEventListener( MouseEvent.CLICK , onSkillButtonClick );
			playerCommandMC.skillButton.addEventListener( MouseEvent.MOUSE_MOVE , onButtonMouseMove );
			playerCommandMC.skillButton.addEventListener( MouseEvent.MOUSE_OUT , onMouseOut );
			playerCommandMC.getButton.addEventListener( MouseEvent.CLICK , onGetButtonClick );
			playerCommandMC.getButton.addEventListener( MouseEvent.MOUSE_MOVE , onButtonMouseMove );
			playerCommandMC.getButton.addEventListener( MouseEvent.MOUSE_OUT , onMouseOut );
			playerCommandMC.helpButton.addEventListener( MouseEvent.CLICK , onHelpButtonClick );
			playerCommandMC.helpButton.addEventListener( MouseEvent.MOUSE_MOVE , onButtonMouseMove );
			playerCommandMC.helpButton.addEventListener( MouseEvent.MOUSE_OUT , onMouseOut );
			playerCommandMC.defenceButton.addEventListener( MouseEvent.CLICK , onDefenceButtonClick );
			playerCommandMC.defenceButton.addEventListener( MouseEvent.MOUSE_MOVE , onButtonMouseMove );
			playerCommandMC.defenceButton.addEventListener( MouseEvent.MOUSE_OUT , onMouseOut );
			playerCommandMC.itemButton.addEventListener( MouseEvent.CLICK , onItemButtonClick );
			playerCommandMC.itemButton.addEventListener( MouseEvent.MOUSE_MOVE , onButtonMouseMove );
			playerCommandMC.itemButton.addEventListener( MouseEvent.MOUSE_OUT , onMouseOut );
			playerCommandMC.petButton.addEventListener( MouseEvent.CLICK , onPetButtonClick );
			playerCommandMC.petButton.addEventListener( MouseEvent.MOUSE_MOVE , onButtonMouseMove );
			playerCommandMC.petButton.addEventListener( MouseEvent.MOUSE_OUT , onMouseOut );
			playerCommandMC.escapeButton.addEventListener( MouseEvent.CLICK , onEscapeButtonClick );
			playerCommandMC.escapeButton.addEventListener( MouseEvent.MOUSE_MOVE , onButtonMouseMove );
			playerCommandMC.escapeButton.addEventListener( MouseEvent.MOUSE_OUT , onMouseOut );



			playerCommandMC.attackUp.mouseEnabled = false;
			playerCommandMC.attackDown.mouseEnabled = false;
			playerCommandMC.magicUp.mouseEnabled = false;
			playerCommandMC.magicDown.mouseEnabled = false;
			playerCommandMC.skillUp.mouseEnabled = false;
			playerCommandMC.skillDown.mouseEnabled = false;
			playerCommandMC.getUp.mouseEnabled = false;
			playerCommandMC.getDown.mouseEnabled = false;
			playerCommandMC.helpUp.mouseEnabled = false;
			playerCommandMC.helpDown.mouseEnabled = false;
			playerCommandMC.defenceUp.mouseEnabled = false;
			playerCommandMC.defenceDown.mouseEnabled = false;
			playerCommandMC.itemUp.mouseEnabled = false;
			playerCommandMC.itemDown.mouseEnabled = false;
			playerCommandMC.petUp.mouseEnabled = false;
			playerCommandMC.petDown.mouseEnabled = false;
			playerCommandMC.escapeUp.mouseEnabled = false;
			playerCommandMC.escapeDown.mouseEnabled = false;

			msgMc.mouseEnabled = false;
			msgMc.mouseChildren = false;
			msgMc.msgText.selectable = false;

			number = new Array();
			number.push( number0 );
			number.push( number1 );
			number.push( number2 );
			number.push( number3 );
			number.push( number4 );
			number.push( number5 );
			number.push( number6 );
			number.push( number7 );
			number.push( number8 );
			number.push( number9 );
			number.push( number00 );
			//10;
			number.push( number10 );
			//11;
			number.push( number20 );
			//12;
			number.push( number30 );
			//13;


			buttons.push( playerButton0 );
			buttons.push( playerButton1 );
			buttons.push( playerButton2 );
			buttons.push( playerButton3 );
			buttons.push( playerButton4 );
			buttons.push( playerButton5 );
			buttons.push( playerButton6 );
			buttons.push( playerButton7 );
			buttons.push( playerButton8 );

			buttons.push( petButton0 );
			buttons.push( petButton1 );
			buttons.push( petButton2 );
			buttons.push( petButton3 );
			buttons.push( petButton4 );
			buttons.push( petButton5 );
			buttons.push( petButton6 );
			buttons.push( petButton7 );
			buttons.push( petButton8 );

			buttons.push( enemyButton0 );
			buttons.push( enemyButton1 );
			buttons.push( enemyButton2 );
			buttons.push( enemyButton3 );
			buttons.push( enemyButton4 );
			buttons.push( enemyButton5 );
			buttons.push( enemyButton6 );
			buttons.push( enemyButton7 );
			buttons.push( enemyButton8 );

			buttons.push( enemyPetButton0 );
			buttons.push( enemyPetButton1 );
			buttons.push( enemyPetButton2 );
			buttons.push( enemyPetButton3 );
			buttons.push( enemyPetButton4 );
			buttons.push( enemyPetButton5 );
			buttons.push( enemyPetButton6 );
			buttons.push( enemyPetButton7 );
			buttons.push( enemyPetButton8 );


			//initUI();
			//startTimer();
		}

		public function startTimer():void
		{
			time = 30;
			timer.start();

			for (var i = 0; i < number.length; i++)
			{
				number[i].visible = false;
			}

			number[13].visible = true;
			number[0].visible = true;
		}

		public function stopTimer():void
		{
			timer.stop();

			for (var i = 0; i < number.length; i++)
			{
				number[i].visible = false;
			}
		}

		public function getTime():int
		{
			return time;
		}

		public function onTimer( e:TimerEvent ):void
		{
			time--;

			for (var i = 0; i < number.length; i++)
			{
				number[i].visible = false;
			}

			if (time == 0)
			{
				timer.stop();
			}

			var n1:int = time / 10;
			var n2:int = time % 10;

			number[n2].visible = true;


			switch ( n1 )
			{
				case 0 :
					number[10].visible = true;
					break;
				case 1 :
					number[11].visible = true;
					break;
				case 2 :
					number[12].visible = true;
					break;
				case 3 :
					number[13].visible = true;
					break;
			}

		}

		public function Clear():void
		{
			for (var i:int = 0; i < buttons.length; ++i)
			{
				buttons[i].clear();
			}
		}

		public function setState( s:int ):void
		{
			switch ( s )
			{
				case READY :
					break;
				case COMMNAD :
					playerCommandMC.visible = true;

					playerCommandMC.attackUp.visible = false;
					playerCommandMC.attackDown.visible = true;
					playerCommandMC.magicUp.visible = true;
					playerCommandMC.magicDown.visible = false;
					playerCommandMC.skillUp.visible = true;
					playerCommandMC.skillDown.visible = false;
					playerCommandMC.getUp.visible = true;
					playerCommandMC.getDown.visible = false;
					playerCommandMC.helpUp.visible = true;
					playerCommandMC.helpDown.visible = false;
					playerCommandMC.defenceUp.visible = true;
					playerCommandMC.defenceDown.visible = false;
					playerCommandMC.itemUp.visible = true;
					playerCommandMC.itemDown.visible = false;
					playerCommandMC.petUp.visible = true;
					playerCommandMC.petDown.visible = false;
					playerCommandMC.escapeUp.visible = true;
					playerCommandMC.escapeDown.visible = false;

					msgMc.visible = true;
					msgMc.msgText.text = "请选择攻击对象";
					break;
				case WAIT :
					playerCommandMC.visible = false;
					msgMc.visible = false;
					stopTimer();
					break;
				case RESULT :
					break;
				case OVER :
					break;
			}

		}


		private function onMouseOut( e:MouseEvent )
		{
			textFiled.visible = false;
		}

		private function onAttackButtonClick( e:MouseEvent )
		{
			playerCommandMC.attackUp.visible = false;
			playerCommandMC.attackDown.visible = true;
			playerCommandMC.magicUp.visible = true;
			playerCommandMC.magicDown.visible = false;
			playerCommandMC.skillUp.visible = true;
			playerCommandMC.skillDown.visible = false;
			playerCommandMC.getUp.visible = true;
			playerCommandMC.getDown.visible = false;
			playerCommandMC.defenceUp.visible = true;
			playerCommandMC.defenceDown.visible = false;
			playerCommandMC.itemUp.visible = true;
			playerCommandMC.itemDown.visible = false;
			playerCommandMC.petUp.visible = true;
			playerCommandMC.petDown.visible = false;
			playerCommandMC.escapeUp.visible = true;
			playerCommandMC.escapeDown.visible = false;

			msgMc.visible = true;
			msgMc.msgText.text = "请选择攻击对象";
		}
		private function onMagicButtonClick( e:MouseEvent )
		{
			playerCommandMC.attackUp.visible = true;
			playerCommandMC.attackDown.visible = false;
			playerCommandMC.magicUp.visible = false;
			playerCommandMC.magicDown.visible = true;
			playerCommandMC.skillUp.visible = true;
			playerCommandMC.skillDown.visible = false;
			playerCommandMC.getUp.visible = true;
			playerCommandMC.getDown.visible = false;
			playerCommandMC.defenceUp.visible = true;
			playerCommandMC.defenceDown.visible = false;
			playerCommandMC.itemUp.visible = true;
			playerCommandMC.itemDown.visible = false;
			playerCommandMC.petUp.visible = true;
			playerCommandMC.petDown.visible = false;
			playerCommandMC.escapeUp.visible = true;
			playerCommandMC.escapeDown.visible = false;

			msgMc.visible = true;
			msgMc.msgText.text = "请选择咒术";
		}
		private function onSkillButtonClick( e:MouseEvent )
		{
			playerCommandMC.attackUp.visible = true;
			playerCommandMC.attackDown.visible = false;
			playerCommandMC.magicUp.visible = true;;
			playerCommandMC.magicDown.visible = false;
			playerCommandMC.skillUp.visible = false;
			playerCommandMC.skillDown.visible = true;
			playerCommandMC.getUp.visible = true;
			playerCommandMC.getDown.visible = false;
			playerCommandMC.defenceUp.visible = true;
			playerCommandMC.defenceDown.visible = false;
			playerCommandMC.itemUp.visible = true;
			playerCommandMC.itemDown.visible = false;
			playerCommandMC.petUp.visible = true;
			playerCommandMC.petDown.visible = false;
			playerCommandMC.escapeUp.visible = true;
			playerCommandMC.escapeDown.visible = false;

			msgMc.visible = true;
			msgMc.msgText.text = "请选择技能";
		}
		private function onGetButtonClick( e:MouseEvent )
		{
			playerCommandMC.attackUp.visible = true;
			playerCommandMC.attackDown.visible = false;
			playerCommandMC.magicUp.visible = true;;
			playerCommandMC.magicDown.visible = false;
			playerCommandMC.skillUp.visible = true;
			playerCommandMC.skillDown.visible = false;
			playerCommandMC.getUp.visible = false;
			playerCommandMC.getDown.visible = true;
			playerCommandMC.defenceUp.visible = true;
			playerCommandMC.defenceDown.visible = false;
			playerCommandMC.itemUp.visible = true;
			playerCommandMC.itemDown.visible = false;
			playerCommandMC.petUp.visible = true;
			playerCommandMC.petDown.visible = false;
			playerCommandMC.escapeUp.visible = true;
			playerCommandMC.escapeDown.visible = false;

			msgMc.visible = true;
			msgMc.msgText.text = "请选择捕捉对象";
		}
		private function onHelpButtonClick( e:MouseEvent )
		{
			playerCommandMC.helpUp.visible = ! playerCommandMC.helpUp.visible;
			playerCommandMC.helpDown.visible = ! playerCommandMC.helpDown.visible;
			msgMc.visible = true;

			if (playerCommandMC.helpUp.visible)
			{
				msgMc.msgText.text = "你关闭了求救";
			}
			else
			{
				msgMc.msgText.text = "你发出了求救";
			}


		}
		private function onDefenceButtonClick( e:MouseEvent )
		{
			playerCommandMC.attackUp.visible = true;
			playerCommandMC.attackDown.visible = false;
			playerCommandMC.magicUp.visible = true;;
			playerCommandMC.magicDown.visible = false;
			playerCommandMC.skillUp.visible = true;
			playerCommandMC.skillDown.visible = false;
			playerCommandMC.getUp.visible = true;
			playerCommandMC.getDown.visible = false;
			playerCommandMC.defenceUp.visible = false;
			playerCommandMC.defenceDown.visible = true;
			playerCommandMC.itemUp.visible = true;
			playerCommandMC.itemDown.visible = false;
			playerCommandMC.petUp.visible = true;
			playerCommandMC.petDown.visible = false;
			playerCommandMC.escapeUp.visible = true;
			playerCommandMC.escapeDown.visible = false;

			msgMc.visible = false;
		}
		private function onItemButtonClick( e:MouseEvent )
		{
			playerCommandMC.attackUp.visible = true;
			playerCommandMC.attackDown.visible = false;
			playerCommandMC.magicUp.visible = true;;
			playerCommandMC.magicDown.visible = false;
			playerCommandMC.skillUp.visible = true;
			playerCommandMC.skillDown.visible = false;
			playerCommandMC.getUp.visible = true;
			playerCommandMC.getDown.visible = false;
			playerCommandMC.defenceUp.visible = true;
			playerCommandMC.defenceDown.visible = false;
			playerCommandMC.itemUp.visible = false;
			playerCommandMC.itemDown.visible = true;
			playerCommandMC.petUp.visible = true;
			playerCommandMC.petDown.visible = false;
			playerCommandMC.escapeUp.visible = true;
			playerCommandMC.escapeDown.visible = false;

			msgMc.visible = true;
			msgMc.msgText.text = "请选择道具";
		}
		private function onPetButtonClick( e:MouseEvent )
		{
			playerCommandMC.attackUp.visible = true;
			playerCommandMC.attackDown.visible = false;
			playerCommandMC.magicUp.visible = true;;
			playerCommandMC.magicDown.visible = false;
			playerCommandMC.skillUp.visible = true;
			playerCommandMC.skillDown.visible = false;
			playerCommandMC.getUp.visible = true;
			playerCommandMC.getDown.visible = false;
			playerCommandMC.defenceUp.visible = true;
			playerCommandMC.defenceDown.visible = false;
			playerCommandMC.itemUp.visible = true;
			playerCommandMC.itemDown.visible = false;
			playerCommandMC.petUp.visible = false;
			playerCommandMC.petDown.visible = true;
			playerCommandMC.escapeUp.visible = true;
			playerCommandMC.escapeDown.visible = false;

			msgMc.visible = true;
			msgMc.msgText.text = "请选择替换的宠物";
		}
		private function onEscapeButtonClick( e:MouseEvent )
		{
			playerCommandMC.attackUp.visible = true;
			playerCommandMC.attackDown.visible = false;
			playerCommandMC.magicUp.visible = true;;
			playerCommandMC.magicDown.visible = false;
			playerCommandMC.skillUp.visible = true;
			playerCommandMC.skillDown.visible = false;
			playerCommandMC.getUp.visible = true;
			playerCommandMC.getDown.visible = false;
			playerCommandMC.defenceUp.visible = true;
			playerCommandMC.defenceDown.visible = false;
			playerCommandMC.itemUp.visible = true;
			playerCommandMC.itemDown.visible = false;
			playerCommandMC.petUp.visible = true;
			playerCommandMC.petDown.visible = false;
			playerCommandMC.escapeUp.visible = false;
			playerCommandMC.escapeDown.visible = true;

			msgMc.visible = false;
		}


		private function onButtonMouseMove( e:MouseEvent )
		{
			textFiled.visible = true;
			textFiled.x = e.target.x + 5;
			textFiled.y = e.target.y + 5;

			switch ( e.target )
			{
				case playerCommandMC.attackButton :
					textFiled.text = "攻击";
					break;
				case playerCommandMC.magicButton :
					textFiled.text = "咒术";
					break;
				case playerCommandMC.skillButton :
					textFiled.text = "技能";
					break;
				case playerCommandMC.getButton :
					textFiled.text = "捕捉";
					break;
				case playerCommandMC.helpButton :
					textFiled.text = "求救";
					break;
				case playerCommandMC.defenceButton :
					textFiled.text = "防御";
					break;
				case playerCommandMC.itemButton :
					textFiled.text = "道具";
					break;
				case playerCommandMC.petButton :
					textFiled.text = "宠物";
					break;
				case playerCommandMC.escapeButton :
					textFiled.text = "逃跑";
					break;
			}

		}




		public function init( playerNum:int , enemyNum:int , pvp:Boolean ):void
		{
			playerArray.length = 0;
			playerPetArray.length = 0;
			enemyArray.length = 0;
			enemyPetArray.length = 0;

			playerButton0.visible = false;
			playerButton1.visible = false;
			playerButton2.visible = false;
			playerButton3.visible = false;
			playerButton4.visible = false;
			playerButton5.visible = false;
			playerButton6.visible = false;
			playerButton7.visible = false;
			playerButton8.visible = false;

			petButton0.visible = false;
			petButton1.visible = false;
			petButton2.visible = false;
			petButton3.visible = false;
			petButton4.visible = false;
			petButton5.visible = false;
			petButton6.visible = false;
			petButton7.visible = false;
			petButton8.visible = false;

			enemyButton0.visible = false;
			enemyButton1.visible = false;
			enemyButton2.visible = false;
			enemyButton3.visible = false;
			enemyButton4.visible = false;
			enemyButton5.visible = false;
			enemyButton6.visible = false;
			enemyButton7.visible = false;
			enemyButton8.visible = false;

			enemyPetButton0.visible = false;
			enemyPetButton1.visible = false;
			enemyPetButton2.visible = false;
			enemyPetButton3.visible = false;
			enemyPetButton4.visible = false;
			enemyPetButton5.visible = false;
			enemyPetButton6.visible = false;
			enemyPetButton7.visible = false;
			enemyPetButton8.visible = false;



			if (pvp)
			{
				switch ( enemyNum )
				{
					case 1 :
						enemyArray.push( enemyButton4 );
						enemyButton4.visible = true;
						enemyButton4.type = 0;

						enemyPetArray.push( enemyPetButton4 );
						enemyPetButton4.visible = true;
						enemyPetButton4.type = 1;
						break;
					case 2 :
						enemyArray.push( enemyButton3 );
						enemyButton3.visible = true;
						enemyButton3.type = 0;
						enemyArray.push( enemyButton5 );
						enemyButton5.visible = true;
						enemyButton5.type = 0;

						enemyPetArray.push( enemyPetButton3 );
						enemyPetButton3.visible = true;
						enemyPetButton3.type = 1;
						enemyPetArray.push( enemyPetButton5 );
						enemyPetButton5.visible = true;
						enemyPetButton5.type = 1;
						break;
					case 3 :
						enemyArray.push( enemyButton2 );
						enemyButton2.visible = true;
						enemyButton2.type = 0;
						enemyArray.push( enemyButton4 );
						enemyButton4.visible = true;
						enemyButton4.type = 0;
						enemyArray.push( enemyButton6 );
						enemyButton6.visible = true;
						enemyButton6.type = 0;

						enemyPetArray.push( enemyPetButton2 );
						enemyPetButton2.visible = true;
						enemyPetButton2.type = 1;
						enemyPetArray.push( enemyPetButton4 );
						enemyPetButton4.visible = true;
						enemyPetButton4.type = 1;
						enemyPetArray.push( enemyPetButton6 );
						enemyPetButton6.visible = true;
						enemyPetButton6.type = 1;
						break;
					case 4 :
						enemyArray.push( enemyButton1 );
						enemyButton1.visible = true;
						enemyButton1.type = 0;
						enemyArray.push( enemyButton3 );
						enemyButton3.visible = true;
						enemyButton3.type = 0;
						enemyArray.push( enemyButton5 );
						enemyButton5.visible = true;
						enemyButton5.type = 0;
						enemyArray.push( enemyButton7 );
						enemyButton7.visible = true;
						enemyButton7.type = 0;

						enemyPetArray.push( enemyPetButton1 );
						enemyPetButton1.visible = true;
						enemyPetButton1.type = 1;
						enemyPetArray.push( enemyPetButton3 );
						enemyPetButton3.visible = true;
						enemyPetButton3.type = 1;
						enemyPetArray.push( enemyPetButton5 );
						enemyPetButton5.visible = true;
						enemyPetButton5.type = 1;
						enemyPetArray.push( enemyPetButton7 );
						enemyPetButton7.visible = true;
						enemyPetButton7.type = 1;
						break;
					case 5 :
						enemyArray.push( enemyButton0 );
						enemyButton0.visible = true;
						enemyButton0.type = 0;
						enemyArray.push( enemyButton2 );
						enemyButton2.visible = true;
						enemyButton2.type = 0;
						enemyArray.push( enemyButton4 );
						enemyButton4.visible = true;
						enemyButton4.type = 0;
						enemyArray.push( enemyButton6 );
						enemyButton6.visible = true;
						enemyButton6.type = 0;
						enemyArray.push( enemyButton8 );
						enemyButton8.visible = true;
						enemyButton8.type = 0;

						enemyPetArray.push( enemyPetButton0 );
						enemyPetButton0.visible = true;
						enemyPetButton0.type = 1;
						enemyPetArray.push( enemyPetButton2 );
						enemyPetButton2.visible = true;
						enemyPetButton2.type = 1;
						enemyPetArray.push( enemyPetButton4 );
						enemyPetButton4.visible = true;
						enemyPetButton4.type = 1;
						enemyPetArray.push( enemyPetButton6 );
						enemyPetButton6.visible = true;
						enemyPetButton6.type = 1;
						enemyPetArray.push( enemyPetButton8 );
						enemyPetButton8.visible = true;
						enemyPetButton8.type = 1;
						break;
				}

			}
			else
			{
				switch ( enemyNum )
				{
					case 1 :
						enemyArray.push( enemyPetButton4 );
						enemyPetButton4.visible = true;
						enemyPetButton4.type = 0;
						enemyPetButton4.index = 0;
						break;
					case 2 :
						enemyArray.push( enemyPetButton3 );
						enemyPetButton3.visible = true;
						enemyPetButton3.type = 0;
						enemyPetButton3.index = 0;
						enemyArray.push( enemyPetButton5 );
						enemyPetButton5.visible = true;
						enemyPetButton5.type = 0;
						enemyPetButton5.index = 1;
						break;
					case 3 :
						enemyArray.push( enemyPetButton2 );
						enemyPetButton2.visible = true;
						enemyPetButton2.type = 0;
						enemyPetButton2.index = 0;
						enemyArray.push( enemyPetButton4 );
						enemyPetButton4.visible = true;
						enemyPetButton4.type = 0;
						enemyPetButton4.index = 1;
						enemyArray.push( enemyPetButton6 );
						enemyPetButton6.visible = true;
						enemyPetButton6.type = 0;
						enemyPetButton6.index = 2;
						break;
					case 4 :
						enemyArray.push( enemyPetButton1 );
						enemyPetButton1.visible = true;
						enemyPetButton1.type = 0;
						enemyPetButton1.index = 0;
						enemyArray.push( enemyPetButton3 );
						enemyPetButton3.visible = true;
						enemyPetButton3.type = 0;
						enemyPetButton3.index = 1;
						enemyArray.push( enemyPetButton5 );
						enemyPetButton5.visible = true;
						enemyPetButton5.type = 0;
						enemyPetButton5.index = 2;
						enemyArray.push( enemyPetButton7 );
						enemyPetButton7.visible = true;
						enemyPetButton7.type = 0;
						enemyPetButton7.index = 3;
						break;
					case 5 :
						enemyArray.push( enemyPetButton0 );
						enemyPetButton0.visible = true;
						enemyPetButton0.type = 0;
						enemyPetButton0.index = 0;
						enemyArray.push( enemyPetButton2 );
						enemyPetButton2.visible = true;
						enemyPetButton2.type = 0;
						enemyPetButton2.index = 1;
						enemyArray.push( enemyPetButton4 );
						enemyPetButton4.visible = true;
						enemyPetButton4.type = 0;
						enemyPetButton4.index = 2;
						enemyArray.push( enemyPetButton6 );
						enemyPetButton6.visible = true;
						enemyPetButton6.type = 0;
						enemyPetButton6.index = 3;
						enemyArray.push( enemyPetButton8 );
						enemyPetButton8.visible = true;
						enemyPetButton8.type = 0;
						enemyPetButton8.index = 4;
						break;
					case 6 :
						enemyArray.push( enemyPetButton0 );
						enemyPetButton0.visible = true;
						enemyPetButton0.type = 0;
						enemyPetButton0.index = 0;
						enemyArray.push( enemyPetButton2 );
						enemyPetButton2.visible = true;
						enemyPetButton2.type = 0;
						enemyPetButton2.index = 1;
						enemyArray.push( enemyPetButton4 );
						enemyPetButton4.visible = true;
						enemyPetButton4.type = 0;
						enemyPetButton4.index = 2;
						enemyArray.push( enemyPetButton6 );
						enemyPetButton6.visible = true;
						enemyPetButton6.type = 0;
						enemyPetButton6.index = 3;
						enemyArray.push( enemyPetButton8 );
						enemyPetButton8.visible = true;
						enemyPetButton8.type = 0;
						enemyPetButton8.index = 4;

						enemyArray.push( enemyButton4 );
						enemyButton4.visible = true;
						enemyButton4.type = 0;
						enemyButton4.index = 5;

						break;
					case 7 :
						enemyArray.push( enemyPetButton0 );
						enemyPetButton0.visible = true;
						enemyPetButton0.type = 0;
						enemyPetButton0.index = 0;
						enemyArray.push( enemyPetButton2 );
						enemyPetButton2.visible = true;
						enemyPetButton2.type = 0;
						enemyPetButton2.index = 1;
						enemyArray.push( enemyPetButton4 );
						enemyPetButton4.visible = true;
						enemyPetButton4.type = 0;
						enemyPetButton4.index = 2;
						enemyArray.push( enemyPetButton6 );
						enemyPetButton6.visible = true;
						enemyPetButton6.type = 0;
						enemyPetButton6.index = 3;
						enemyArray.push( enemyPetButton8 );
						enemyPetButton8.visible = true;
						enemyPetButton8.type = 0;
						enemyPetButton8.index = 4;

						enemyArray.push( enemyButton3 );
						enemyButton3.visible = true;
						enemyButton3.type = 0;
						enemyButton3.index = 5;
						enemyArray.push( enemyButton5 );
						enemyButton5.visible = true;
						enemyButton5.type = 0;
						enemyButton5.index = 6;

						break;
					case 8 :
						enemyArray.push( enemyPetButton0 );
						enemyPetButton0.visible = true;
						enemyPetButton0.type = 0;
						enemyPetButton0.index = 0;
						enemyArray.push( enemyPetButton2 );
						enemyPetButton2.visible = true;
						enemyPetButton2.type = 0;
						enemyPetButton2.index = 1;
						enemyArray.push( enemyPetButton4 );
						enemyPetButton4.visible = true;
						enemyPetButton4.type = 0;
						enemyPetButton4.index = 2;
						enemyArray.push( enemyPetButton6 );
						enemyPetButton6.visible = true;
						enemyPetButton6.type = 0;
						enemyPetButton6.index = 3;
						enemyArray.push( enemyPetButton8 );
						enemyPetButton8.visible = true;
						enemyPetButton8.type = 0;
						enemyPetButton8.index = 4;

						enemyArray.push( enemyButton2 );
						enemyButton2.visible = true;
						enemyButton2.type = 0;
						enemyButton2.index = 5;
						enemyArray.push( enemyButton4 );
						enemyButton4.visible = true;
						enemyButton4.type = 0;
						enemyButton4.index = 6;
						enemyArray.push( enemyButton6 );
						enemyButton6.visible = true;
						enemyButton6.type = 0;
						enemyButton6.index = 7;
						break;
					case 9 :
						enemyArray.push( enemyPetButton0 );
						enemyPetButton0.visible = true;
						enemyPetButton0.type = 0;
						enemyPetButton0.index = 0;
						enemyArray.push( enemyPetButton2 );
						enemyPetButton2.visible = true;
						enemyPetButton2.type = 0;
						enemyPetButton2.index = 1;
						enemyArray.push( enemyPetButton4 );
						enemyPetButton4.visible = true;
						enemyPetButton4.type = 0;
						enemyPetButton4.index = 2;
						enemyArray.push( enemyPetButton6 );
						enemyPetButton6.visible = true;
						enemyPetButton6.type = 0;
						enemyPetButton6.index = 3;
						enemyArray.push( enemyPetButton8 );
						enemyPetButton8.visible = true;
						enemyPetButton8.type = 0;
						enemyPetButton8.index = 4;

						enemyArray.push( enemyButton1 );
						enemyButton1.visible = true;
						enemyButton1.type = 0;
						enemyButton1.index = 5;
						enemyArray.push( enemyButton3 );
						enemyButton3.visible = true;
						enemyButton3.type = 0;
						enemyButton3.index = 6;
						enemyArray.push( enemyButton5 );
						enemyButton5.visible = true;
						enemyButton5.type = 0;
						enemyButton5.index = 7;
						enemyArray.push( enemyButton7 );
						enemyButton7.visible = true;
						enemyButton7.type = 0;
						enemyButton7.index = 8;
						break;
					case 10 :
						enemyArray.push( enemyPetButton0 );
						enemyPetButton0.visible = true;
						enemyPetButton0.type = 0;
						enemyPetButton0.index = 0;
						enemyArray.push( enemyPetButton2 );
						enemyPetButton2.visible = true;
						enemyPetButton2.type = 0;
						enemyPetButton2.index = 1;
						enemyArray.push( enemyPetButton5 );
						enemyPetButton5.visible = true;
						enemyPetButton5.type = 0;
						enemyPetButton5.index = 2;
						enemyArray.push( enemyPetButton6 );
						enemyPetButton6.visible = true;
						enemyPetButton6.type = 0;
						enemyPetButton6.index = 3;
						enemyArray.push( enemyPetButton8 );
						enemyPetButton8.visible = true;
						enemyPetButton8.type = 0;
						enemyPetButton8.index = 4;

						enemyArray.push( enemyButton0 );
						enemyButton0.visible = true;
						enemyButton0.type = 0;
						enemyButton0.index = 5;
						enemyArray.push( enemyButton2 );
						enemyButton2.visible = true;
						enemyButton2.type = 0;
						enemyButton2.index = 6;
						enemyArray.push( enemyButton4 );
						enemyButton4.visible = true;
						enemyButton4.type = 0;
						enemyButton4.index = 7;
						enemyArray.push( enemyButton6 );
						enemyButton6.visible = true;
						enemyButton6.type = 0;
						enemyButton6.index = 8;
						enemyArray.push( enemyButton8 );
						enemyButton8.visible = true;
						enemyButton8.type = 0;
						enemyButton8.index = 9;
						break;
				}
			}




			switch ( playerNum )
			{
				case 1 :
					playerArray.push( playerButton4 );
					playerButton4.visible = true;
					playerButton4.type = 0;
					playerButton4.index = 0;

					playerPetArray.push( petButton4 );
					petButton4.visible = true;
					petButton4.type = 1;
					petButton4.index = 0;

					break;
				case 2 :
					playerArray.push( playerButton3 );
					playerButton3.visible = true;
					playerButton3.type = 0;
					playerButton3.index = 0;
					playerArray.push( playerButton5 );
					playerButton5.visible = true;
					playerButton5.type = 0;
					playerButton5.index = 1;

					playerPetArray.push( petButton3 );
					petButton3.visible = true;
					petButton3.type = 1;
					petButton3.index = 0;
					playerPetArray.push( petButton5 );
					petButton5.visible = true;
					petButton5.type = 1;
					petButton5.index = 1;

					break;
				case 3 :
					playerArray.push( playerButton2 );
					playerButton2.visible = true;
					playerButton2.type = 0;
					playerButton2.index = 0;
					playerArray.push( playerButton4 );
					playerButton4.visible = true;
					playerButton4.type = 0;
					playerButton4.index = 1;
					playerArray.push( playerButton6 );
					playerButton6.visible = true;
					playerButton6.type = 0;
					playerButton6.index = 2;

					playerPetArray.push( petButton2 );
					petButton2.visible = true;
					petButton2.type = 1;
					petButton2.index = 0;
					playerPetArray.push( petButton4 );
					petButton4.visible = true;
					petButton4.type = 1;
					petButton4.index = 1;
					playerPetArray.push( petButton6 );
					petButton6.visible = true;
					petButton6.type = 1;
					petButton6.index = 2;
					break;
				case 4 :
					playerArray.push( playerButton1 );
					playerButton1.visible = true;
					playerButton1.type = 0;
					playerButton1.index = 0;
					playerArray.push( playerButton3 );
					playerButton3.visible = true;
					playerButton3.type = 0;
					playerButton3.index = 1;
					playerArray.push( playerButton5 );
					playerButton5.visible = true;
					playerButton5.type = 0;
					playerButton5.index = 2;
					playerArray.push( playerButton7 );
					playerButton7.visible = true;
					playerButton7.type = 0;
					playerButton7.index = 3;

					playerPetArray.push( petButton1 );
					petButton1.visible = true;
					petButton1.type = 1;
					petButton1.index = 0;
					playerPetArray.push( petButton3 );
					petButton3.visible = true;
					petButton3.type = 1;
					petButton3.index = 1;
					playerPetArray.push( petButton5 );
					petButton5.visible = true;
					petButton5.type = 1;
					petButton5.index = 2;
					playerPetArray.push( petButton7 );
					petButton7.visible = true;
					petButton7.type = 1;
					petButton7.index = 3;
					break;
				case 5 :
					playerArray.push( playerButton0 );
					playerButton0.visible = true;
					playerButton0.type = 0;
					playerButton0.index = 0;
					playerArray.push( playerButton2 );
					playerButton2.visible = true;
					playerButton2.type = 0;
					playerButton2.index = 1;
					playerArray.push( playerButton4 );
					playerButton4.visible = true;
					playerButton4.type = 0;
					playerButton4.index = 2;
					playerArray.push( playerButton6 );
					playerButton6.visible = true;
					playerButton6.type = 0;
					playerButton6.index = 3;
					playerArray.push( playerButton8 );
					playerButton8.visible = true;
					playerButton8.type = 0;
					playerButton8.index = 4;

					playerPetArray.push( petButton0 );
					petButton0.visible = true;
					petButton0.type = 1;
					petButton0.index = 0;
					playerPetArray.push( petButton2 );
					petButton2.visible = true;
					petButton2.type = 1;
					petButton2.index = 1;
					playerPetArray.push( petButton4 );
					petButton4.visible = true;
					petButton4.type = 1;
					petButton4.index = 2;
					playerPetArray.push( petButton6 );
					petButton6.visible = true;
					petButton6.type = 1;
					petButton6.index = 3;
					playerPetArray.push( petButton8 );
					petButton8.visible = true;
					petButton8.type = 1;
					petButton8.index = 4;
					break;

			}


		}
	}

}